/**
 * This class represents a client session and stores the server, user and client settings for a
 * particular client session.
 */
package org.hackystat.ui.telemetryviewer.client.common;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * @author David J. Nickles
 * 
 */
public class Session implements Serializable {

  /**
   * Serializable ID.
   */
  private static final long serialVersionUID = 3088401830903088120L;
  /** {@literal} DEFAULT default project name. */  
  public static final String DEFAULT = "Default"; 
  /** {@literal} COOKIESPAN the expiration of the cookie. */  
  public static final long COOKIETIME = (1000L * 60L * 60L * 24L * 365L); 
  
  private String sensorbaseHost;
  private String telemetryHost;
  private String user;
  private String password;
  private ArrayList projects;
  private int selectedIndex;

  /**
   * Get the sesnor  base host URI for this session.
   * @return the sensorbaseHost
   */
  public String getSensorbaseHost() {
    return sensorbaseHost;
  }

  /**
   * Get the telemetry host URI for this session.
   * @return the telemetryHost
   */
  public String getTelemetryHost() {
    return telemetryHost;
  }

  /**
   * Get the user's name for this session.
   * @return the user
   */
  public String getUser() {
    return user;
  }

  /**
   * Get the user's password for this session.
   * @return the password
   */
  public String getPassword() {
    return password;
  }

  /**
   * Set the sensor base host for this session.
   * @param sensorbaseHost the sensorbaseHost to set
   */
  public void setSensorbaseHost(String sensorbaseHost) {
    this.sensorbaseHost = sensorbaseHost;
  }

  /**
   * Set the telemetry host for this session.
   * @param telemetryHost the telemetryHost to set.
   */
  public void setTelemetryHost(String telemetryHost) {
    this.telemetryHost = telemetryHost;
  }

  /**
   * Set the user name for this session.
   * @param user the user to set.
   */
  public void setUser(String user) {
    this.user = user;
  }

  /**
   * Set the user password for this session.
   * @param password the password to set.
   */
  public void setPassword(String password) {
    this.password = password;
  }

  /** 
   * Get the composite list of the projects and project attributes for this user.
   * @return the composite list of the projects and project attributes for this user.
   * 
   * @gwt.typeArgs <org.hackystat.ui.telemetryviewer.client.common.ProjectParcel> 
   */
  public ArrayList getProjectList() {
    return projects;
  }

  /** 
   * Set the composite list of the projects and project attributes for this user.
   * @param projects a composite list of the projects and project attributes for this user.
   * 
   * @gwt.typeArgs projects <org.hackystat.ui.telemetryviewer.client.common.ProjectParcel>
   */
  public void setProjectList(ArrayList projects) {
    this.projects = projects;
  }

  /** 
   * Designate a project as selected.
   * @param index of the user selected project to set.
   */
  public void markProjectSelected(int index) {
    ((ProjectParcel)this.projects.get(index)).setSelected(Boolean.TRUE);
  }
  
  /**
   * This method returns a string representation of the values of this session.
   * @return a string representation of the values of this session.
   */
  public String toString() {
    return "{Sensorbase: " + this.sensorbaseHost + ", Telemetry: " + this.telemetryHost
      + ", User: " + this.user + "\n" + "Projects: " + this.projects + "}";
  }
}
